﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Master.Bean;
using Shpm.System;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Utils;

public partial class App_Input_EvaluationUpdForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.ViewState["CURRICULUM_ID"] = this.Context.Items["CURRICULUM_ID"];
            initDic();
            tbl2.Visible = false;

            if (Context.Items.Contains("NAME"))
            {
                this.ViewState["NAME"] = Context.Items["NAME"];
            }
            if (Context.Items.Contains("TYPE"))
            {
                this.ViewState["TYPE"] = Context.Items["TYPE"];
            }
            if (Context.Items.Contains("DO"))
            {
                this.ViewState["DO"] = Context.Items["DO"];
            }
            btnAdd.Enabled = false;
        }
    }
    protected void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
    {
        string studentId = Convert.ToString((sender as GridView).DataKeys[e.NewEditIndex].Values[0]);
        this.ViewState["STUDENT_ID"] = studentId;
        this.lblName.Text = this.GridView1.Rows[e.NewEditIndex].Cells[1].Text;
        EvaluationUpdBean dataBean = new EvaluationUpdBean();
        EvaluationSrhDao Dao = new EvaluationSrhDao();

        dataBean.StudentId = Convert.ToInt32(this.ViewState["STUDENT_ID"]);

        dataBean = Dao.GetStudent(dataBean);
        if (dataBean != null)
        {
            if (dataBean.CurriculumYinxiang != "")
            {
                CurriculumYinxiang.SelectedValue = dataBean.CurriculumYinxiang;
            }
            if (dataBean.TeacherTaidu != "")
            {
                TeacherTaidu.SelectedValue = dataBean.TeacherTaidu;
            }
            if (dataBean.TeacherNeirong != "")
            {
                TeacherNeirong.SelectedValue = dataBean.TeacherNeirong;
            }
            if (dataBean.TeacherFangfa != "")
            {
                TeacherFangfa.SelectedValue = dataBean.TeacherFangfa;
            }
            if (dataBean.TeacherGuanli != "")
            {
                TeacherGuanli.SelectedValue = dataBean.TeacherGuanli;
            }
            if (dataBean.TeacherXiaoguo != "")
            {
                TeacherXiaoguo.SelectedValue = dataBean.TeacherXiaoguo;
            }
            if (dataBean.CurriculumQifen != "")
            {
                CurriculumQifen.SelectedValue = dataBean.CurriculumQifen;
            }
            CurriculumTese.Text = dataBean.CurriculumTese;
            CurriculumYijian.Text = dataBean.CurriculumYijian;
            CurriculumJianyi.Text = dataBean.CurriculumJianyi;
        }
        tbl2.Visible = true;
        btnAdd.Enabled = true;
    }

    protected override void OnPreRender(EventArgs e)
    {
        EvaluationUpdBean dataBean = new EvaluationUpdBean();
        EvaluationSrhDao Dao = new EvaluationSrhDao();

        dataBean.CurriculumId = Convert.ToInt32(this.ViewState["CURRICULUM_ID"]);
        IList list = Dao.ListStudent(dataBean);

        GridView1.DataSource = list;
        GridView1.DataBind();
        //if (list.Count == 0)
        //{
        //    tbl1.Visible = false;
        //    tbl2.Visible = false;
        //}
        //else
        //{
        //    tbl1.Visible = true;
        //    tbl2.Visible = true;
        //}
    }

    /*
     * 函数名：initDic
     * 功能：控件数据绑定
     * 参数：无
     * 说明：将数据字典中的数据绑定在指定的控件上
     */
    private void initDic()
    {

        CommonDictionaryBean paramBean = new CommonDictionaryBean();
        CommonDictionaryDao dao = new CommonDictionaryDao();

        paramBean.Catalog = "T_CURRICULUM_STUDENT.PINGGU";
        initAll(dao, paramBean, this.CurriculumYinxiang);
        initAll(dao, paramBean, this.TeacherTaidu);
        initAll(dao, paramBean, this.TeacherNeirong);
        initAll(dao, paramBean, this.TeacherFangfa);
        initAll(dao, paramBean, this.TeacherGuanli);
        initAll(dao, paramBean, this.TeacherXiaoguo);
        initAll(dao, paramBean, this.CurriculumQifen);
    }

    /*
     * 函数名：initAll
     * 功能  ：控件数据绑定
     * 参数  ：dao(数据字典的DAO）
     *       ：paramBean(数据字典的Bean）
     *       ：obj（控件）
     * 说明  ：
     */
    private void initAll(CommonDictionaryDao dao, CommonDictionaryBean paramBean, ListControl obj)
    {
        IList dataList = dao.FindByCatalog(paramBean);

        obj.DataSource = dataList;
        obj.DataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

        EvaluationUpdBean dataBean = new EvaluationUpdBean();
        EvaluationSrhDao Dao = new EvaluationSrhDao();

         dataBean.CurriculumYinxiang=CurriculumYinxiang.SelectedValue;
         dataBean.TeacherTaidu=TeacherTaidu.SelectedValue;
         dataBean.TeacherNeirong=TeacherNeirong.SelectedValue;
         dataBean.TeacherFangfa=TeacherFangfa.SelectedValue;
         dataBean.TeacherGuanli=TeacherGuanli.SelectedValue;
         dataBean.TeacherXiaoguo=TeacherXiaoguo.SelectedValue;
         dataBean.CurriculumQifen=CurriculumQifen.SelectedValue;
         dataBean.CurriculumTese=CurriculumTese.Text;
         dataBean.CurriculumYijian=CurriculumYijian.Text;
         dataBean.CurriculumJianyi=CurriculumJianyi.Text;
         dataBean.StudentId = Convert.ToInt32(ViewState["STUDENT_ID"]);

         Dao.UpdStudent(dataBean);
         ((Design_MasterPage)this.Master).InfoMessage =
                           HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0002").ToString();
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Context.Items["NAME"] = this.ViewState["NAME"];
        Context.Items["TYPE"] = this.ViewState["TYPE"];
        Context.Items["DO"] = this.ViewState["DO"];
        string url = "~/App/Input/EvaluationSrhForm.aspx";
        ControllerUtils.Transfer(Context, url, true); 
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Cells[2].Text = CommonDictionaryUtils.GetContent(CommonDictionaryUtils.M_PERSON_SEX, e.Row.Cells[2].Text); 
            

        }
    }
}
